package com.hanfengyi.system.service.impl;

import com.hanfengyi.system.domain.Employee;
import com.hanfengyi.system.domain.Tenant;
import com.hanfengyi.system.dto.EnteringDTO;
import com.hanfengyi.system.mapper.EmployeeMapper;
import com.hanfengyi.system.mapper.TenantMapper;
import com.hanfengyi.system.service.ITenantService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hfy
 * @since 2020-02-20
 */
@Service
public class TenantServiceImpl extends ServiceImpl<TenantMapper, Tenant> implements ITenantService {
    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public void tenanEenter(EnteringDTO enteringDTO) {
        Date date = new Date();
        //1. 保存租户表
        Tenant tenant = enteringDTO.getTenant();
        tenant.setRegisterTime(date);
        tenant.setState(false);
        baseMapper.insert(tenant);
        //2. 保存员工表
        Employee employee = enteringDTO.getEmployee();
        employee.setInputTime(date);
        employee.setState(Employee.USER_NORMAL);
        employee.setType(Employee.EMPLOYEE_MANAGER);
        employee.setTenantId(tenant.getId());
        employeeMapper.insert(employee);
        //3. 保存租户菜单中间表
        baseMapper.insertTenantAndMeal(tenant.getId(),enteringDTO.getMealId(),0);
    }
}
